/*
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package ui.core.containers;

import java.awt.Image;
import java.io.IOException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import twitter4j.Status;

/**
 * Mostra um tweet
 */
public class Tweet extends javax.swing.JPanel {

    /** Creates new form Tweet */
    public Tweet() {
        initComponents();
    }

    public Tweet(Status status) {
        initComponents();
        loadProfileImage(status.getUser().getProfileImageURL());
        message.setText(status.getText());
    }

    private void loadProfileImage(URL source) {
        Image image = null;
        try {
            image = ImageIO.read(source);
        } catch (IOException ex) {
            Logger.getLogger(Tweet.class.getName()).log(Level.SEVERE, null, ex);
        }
        avatar.setIcon(new ImageIcon(image));
    }

    public JLabel getAvatar() {
        return avatar;
    }

    public JLabel getMessage() {
        return message;
    }

    public void setAvatar(JLabel avatar) {
        this.avatar = avatar;
    }

    public void setMessage(JLabel message) {
        this.message = message;
    }
    
    

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        message = new javax.swing.JLabel();
        avatar = new javax.swing.JLabel();

        setBackground(new java.awt.Color(206, 252, 144));

        message.setText("<html><p>O @zanata_arnos dissecou o Peñarol no Blog do Mauro Cezar. Leitura obrigatória para quem verá a final hoje: http://bit.ly/geFuSC.</p></html>");
        message.setVerticalAlignment(javax.swing.SwingConstants.TOP);

        avatar.setAlignmentY(0.0F);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap(92, Short.MAX_VALUE)
                .add(message, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 368, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(layout.createSequentialGroup()
                    .add(0, 0, 0)
                    .add(avatar)
                    .addContainerGap(460, Short.MAX_VALUE)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(message, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 68, Short.MAX_VALUE)
            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(layout.createSequentialGroup()
                    .add(0, 0, 0)
                    .add(avatar)
                    .addContainerGap(68, Short.MAX_VALUE)))
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel avatar;
    private javax.swing.JLabel message;
    // End of variables declaration//GEN-END:variables
}
